package light.head.dao.oa;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import light.head.constant.Parm;
import light.head.enm.RESULT;
import light.head.framework.base.BaseDAO;
import light.head.framework.entity.PageBean;
import light.head.model.Transfer;


@Service
public class TransferDAO extends BaseDAO<Transfer, Integer> {
	
	
	public RESULT findByMap(Map<String, String> map, PageBean pb){
		StringBuffer hql = new StringBuffer("FROM Transfer t WHERE 1 = 1");
		List<Object> list = null;
		if(null != map) {
			list = new ArrayList<Object>();
			String tName = map.get(Parm.TN);
			String rName = map.get(Parm.RN);
			String title = map.get(Parm.TITLE);
			String de = map.get(Parm.DELETED);
			String oc = map.get(Parm.OC);
			if(isNotNull(tName)) {
				hql.append(" AND t.tName = (SELECT u.code FROM UserInfo u WHERE u.realName like ?)");
				list.add("%" + tName + "%");
			}if(isNotNull(rName)) {
				hql.append(" AND t.rName = (SELECT u.code FROM UserInfo u WHERE u.realName like ?)");
				list.add("%" + rName + "%");
			}if(isNotNull(title)) {
				hql.append(" AND t.title like ?");
				list.add("%" + title + "%");
			}if(isNotNull(de)) {
				hql.append(" AND t.deleted = ?");
				list.add(Boolean.parseBoolean(de));
			}if(isNotNull(oc)) {
				hql.append(" AND t.oc = ?");
				list.add(Integer.parseInt(oc));
			}
			
		}
		
		hql.append(" ORDER BY t.code DESC");
		
		if (findToPageBean(hql.toString(), pb, list) == RESULT.SUCCESS)
			return RESULT.SUCCESS;
		
		return RESULT.ERROR;
	}

}
